<template lang="html">
  <div class="main">
    <div class="main-group">
      <div class="main-body body-left">
        <div class="body">
          <div id="test_chart" class="chart">
          </div>
        </div>
      </div>
      <div class="main-body body-right">
        <div class="body">
          <div id="test_chart2" class="chart">
          </div>
          <div class="chart-title" id="title2" v-show="show">
            吸毒人员比例
          </div>
        </div>
      </div>
    </div>
    <div class="main-menu">
      <div class="menu">
        <span @click="back">上一个</span>
        <span @click="back">返回</span>
        <span @click="back">下一个</span>
      </div>
    </div>
  </div>
</template>

<script>
import {ShMapData} from './sh-map-data';
export default {
  data () {
    return {
      show: true,
      notShowTitle: [
        '虹口区',
        '长宁区',
        '静安区',
        '黄浦区',
        '普陀区',
        '徐汇区',
        '杨浦区'
      ]
    };
  },
  methods: {
    back () {
      this.$router.go(-1);
    },
    draw2 () {
      let chart = this.$echarts.init(document.getElementById('test_chart2'));
      let option = {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        color: ['#2FE0B6', '#01C853', '#FFD741', '#7C4DFF', '#3FC4FF'],
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
              normal: {
                show: false,
                position: 'center'
              },
              emphasis: {
                show: true,
                textStyle: {
                  fontSize: '30',
                  fontWeight: 'bold'
                }
              }
            },
            labelLine: {
              normal: {
                show: false
              }
            },
            data: [
              {value: 335, name: '直接访问'},
              {value: 310, name: '邮件营销'},
              {value: 234, name: '联盟广告'},
              {value: 135, name: '视频广告'},
              {value: 1548, name: '搜索引擎'}
            ]
          }
        ]
      };
      chart.setOption(option);
      chart.on('mouseover', () => {
        this.show = false;
      });
      chart.on('mouseout', () => {
        this.show = true;
      });
    },
    draw () {
      let chart = this.$echarts.init(document.getElementById('test_chart'));
      chart.showLoading();
      chart.hideLoading();

      this.$echarts.registerMap('SH', ShMapData);

      chart.setOption({
        title: {
          text: '上海市涉毒人员密度 （2017）',
          subtext: '人口密度数据来自Wikipedia',
          sublink: 'http://zh.wikipedia.org/wiki/%E9%A6%99%E6%B8%AF%E8%A1%8C%E6%94%BF%E5%8D%80%E5%8A%83#cite_note-12'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{b}<br/>{c} (p / km2)'
        },
        visualMap: {
          min: 800,
          max: 50000,
          text: ['High', 'Low'],
          realtime: false,
          calculable: true,
          inRange: {
            color: ['#FFDAB9', '#FFD741', 'orangered']
          }
        },
        series: [
          {
            name: '上海市19区涉毒人员密度',
            type: 'map',
            selectedMode: 'single',
            mapType: 'SH', // 自定义扩展图表类型
            itemStyle: {
              normal: {label: {
                show: true,
                formatter: (params) => {
                  if (this.notShowTitle.indexOf(params.data.name) !== -1) {
                    return '';
                  }
                }
              }},
              emphasis: {
                label: {show: true
                  // formatter: (params) => {
                  //   return params.data.name;
                  // }
                },
                borderWidth: 2,
                borderColor: '#fff',
                areaColor: 'yellow'
              }
            },
            data: [
              {name: '崇明区', value: 20057.34},
              {name: '奉贤区', value: 31686.1},
              {name: '浦东新区', value: 6992.6},
              {name: '金山区', value: 44045.49},
              {name: '青浦区', value: 40689.64},
              {name: '松江区', value: 37659.78},
              {name: '嘉定区', value: 45180.97},
              {name: '宝山区', value: 55204.26},
              {name: '闵行区', value: 21900.9},
              {name: '杨浦区', value: 4918.26},
              {name: '普陀区', value: 5881.84},
              {name: '徐汇区', value: 4178.01},
              {name: '长宁区', value: 2227.92},
              {name: '虹口区', value: 9172.94},
              {name: '黄浦区', value: 3368},
              {name: '静安区', value: 806.98}
            ]
          }
        ]
      });
    }
  },
  mounted () {
    setTimeout(_ => {
      this.draw();
      this.draw2();
    }, 200);
  }
};
</script>

<style lang="css" scoped>
.main {
  background-image: url('../../assets/bg_all_2.png');
  background-repeat: no-repeat;
  background-size: 100% 100%;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  vertical-align: middle;
  justify-content: center;
  align-items: center;
  text-align: center;
  .main-group {
    width: 70%;
    height: 70%;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    .main-body {
      margin-left: 20px;
      height: 100%;
      box-shadow: 2px 6px 12px 2px rgba(0,0,0,.8);
      border-radius: 4px;
      border: 3px solid #ebeef5;
      background-color: rgba(255,255,255,.95);
      overflow: hidden;
      color: #303133;
      transition: .3s;
      .body {
        padding: 10px;
        height: 100%;
        width: 100%;
        position: relative;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
        .chart {
          width: 100%;
          height: 100%;
        }
        .chart-title {
          position: absolute;
          top: 50%;
          margin-top: -15px;
          height: 30px;
          width: 100%;
          margin-left: -10px;
          text-align: center;
          font-size: 25px;
          color: #999;
          font-weight: 800;
        }
      }
    }
    .main-body:first-child {
      margin-left: 0px;
    }
    .body-left {
      width: 65%;
    }
    .body-right {
      width: 35%;
    }
  }
  .main-menu {
    width: 70%;
    height: 50px;
    margin-top: 15px;
    position: relative;
    .menu {
      font-size: 20px;
      font-family: '微软雅黑';
      color: rgba(255,255,255,0.5);
      display: flex;
      flex-direction: row;
      vertical-align: middle;
      justify-content: center;
      align-items: center;
      text-align: center;
      height: 100%;
      margin-left: 30%;
      margin-right: 30%;
      span {
        display: block;
        flex: 1;
        cursor: pointer;
      }
      span:hover {
        transition: all .3s;
        font-size: 26px;
      }
    }
    .menu::after {
      content: '';
      position: absolute;
      width: 50%;
      height: 20px;
      top: 100%;
      overflow: hidden;
      background-size:100% 100%;
      background-image: url('../../assets/pic_back_tips.png');
    }
  }
}
</style>
